package com.doyens.mapper;

import com.doyens.pojo.Applicant;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ApplicantMapper {

    @Results({
            @Result(id=true,column = "eid",property = "eid"),
            @Result(id=true,column = "photo",property = "photo"),
            @Result(column = "ename",property = "ename"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "education",property = "education"),
            @Result(column = "age",property = "age"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "email",property = "email"),
            @Result(column = "status",property = "status"),
            @Result(column = "eid",property = "interviewers",javaType = List.class,
                        many = @Many(select = "com.doyens.mapper.InterviewerMapper.findById"))
    })
    @Select("select * from applicant")
    List<Applicant> list();

    @Select("select status from applicant group by status")
    List<Applicant> findStatus();

    @Select("select * from applicant group by education")
    List<Applicant> findEducation();

    @Results({
            @Result(id=true,column = "eid",property = "eid"),
            @Result(id=true,column = "photo",property = "photo"),
            @Result(column = "ename",property = "ename"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "education",property = "education"),
            @Result(column = "age",property = "age"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "email",property = "email"),
            @Result(column = "status",property = "status"),
            @Result(column = "eid",property = "interviewers",javaType = List.class,
                    many = @Many(select = "com.doyens.mapper.InterviewerMapper.findById"))
    })
    @Select("select * from applicant where eid=#{id}")
    Applicant findById(String id);

    @Delete("delete from applicant where eid=#{id}")
    Integer del(Integer id);

    @Delete("delete from app_inter where applicantId=#{id}")
    Integer delAl(Integer id);

    @Update("update applicant set ename=#{ename},sex=#{sex},education=#{education},age=#{age},phoneNum=#{phoneNum},email=#{email},status=#{status},textArea=#{textArea} where eid=#{eid}")
    Integer save(Applicant applicant);

    @Insert("insert into app_inter(applicantId,interviewerId) values (#{id1},#{id2})")
    void saveInterviewerName(@Param("id1") Integer id,@Param("id2") Integer interviewerId);

    @Results({
            @Result(id=true,column = "eid",property = "eid"),
            @Result(id=true,column = "photo",property = "photo"),
            @Result(column = "ename",property = "ename"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "education",property = "education"),
            @Result(column = "age",property = "age"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "email",property = "email"),
            @Result(column = "status",property = "status"),
            @Result(column = "eid",property = "interviewers",javaType = List.class,
                    many = @Many(select = "com.doyens.mapper.InterviewerMapper.findById"))
    })
    @Select("select * from applicant where ename like concat('%',#{ename},'%') order by eid")
    List<Applicant> findByEname(String ename);

    @Results({
            @Result(id=true,column = "eid",property = "eid"),
            @Result(id=true,column = "photo",property = "photo"),
            @Result(column = "ename",property = "ename"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "education",property = "education"),
            @Result(column = "age",property = "age"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "email",property = "email"),
            @Result(column = "status",property = "status"),
            @Result(column = "eid",property = "interviewers",javaType = List.class,
                    many = @Many(select = "com.doyens.mapper.InterviewerMapper.findById"))
    })
    @Select("select * from applicant where status=#{status} order by eid")
    List<Applicant> findByStatus(Integer status);

    @Results({
            @Result(id=true,column = "eid",property = "eid"),
            @Result(id=true,column = "photo",property = "photo"),
            @Result(column = "ename",property = "ename"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "education",property = "education"),
            @Result(column = "age",property = "age"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "email",property = "email"),
            @Result(column = "status",property = "status"),
            @Result(column = "eid",property = "interviewers",javaType = List.class,
                    many = @Many(select = "com.doyens.mapper.InterviewerMapper.findById"))
    })
    @Select("select * from applicant where ename like concat('%',#{ename},'%') and status=#{status} order by eid")
    List<Applicant> findByCondition(@Param("ename") String ename, @Param("status") Integer status);
}
